package com.yf.aclient.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.yf.aclient.R;

public class MyAdapter extends BaseAdapter { // 实现列表内容适配器
	private LayoutInflater mInflater;
	public static List<Map<String, Object>> mData;

	public MyAdapter(Context context, List<Map<String, Object>> myData) {
		this.mInflater = LayoutInflater.from(context);
		mData = myData;
	}

	public int getCount() { // 获取列表项个数
		return mData.size();
	}

	public Object getItem(int arg0) {
		return arg0;
	}

	public long getItemId(int arg0) {
		return arg0;
	}

	// 设置每个列表项的显示
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.selectfileview, null); // 设置列表项的布局
			holder.img = (ImageView) convertView.findViewById(R.id.img);
			 holder.name = (TextView) convertView.findViewById(R.id.name);
			 holder.fileSize = (TextView) convertView.findViewById(R.id.fileSize);
			 holder.modifyDate = (TextView) convertView.findViewById(R.id.modifyDate);
			 holder.checkBox = (CheckBox) convertView.findViewById(R.id.checkBox);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.img.setImageDrawable((Drawable) mData.get(position).get(
				"img")); // 根据位置position设置具体内容
//		holder.img.setImageDrawable(getResources().getDrawable(R.drawable.folder))
		holder.name.setText((String) mData.get(position).get("name"));
		holder.fileSize.setText(mData.get(position).get("fileSize").toString());
		holder.modifyDate.setText(mData.get(position).get("modifyDate").toString());
		if((Boolean)mData.get(position).get("isDirectory"))
		holder.checkBox.setVisibility(View.GONE);
		else{
			holder.checkBox.setChecked(false);
		}
		return convertView;
	}

	public final  class ViewHolder { // 定义每个列表项所含内容
		public ImageView img; // 显示图片ID
		public TextView name; // 文件目录名
		public TextView fileSize; // 文件目录描述
		public TextView modifyDate; // 文件目录描述
		public CheckBox  checkBox;
	}
};